package com.douleka.curd.advice;




import com.douleka.curd.exception.MyException;
import com.douleka.curd.utils.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
public class CommonExceptionHandle {
    @ExceptionHandler(NullPointerException.class)
    public Result nullPointerExceptionHandle(NullPointerException ex) {
        ex.printStackTrace();
        return new Result("555", "空指针错误");
    }
    @ExceptionHandler(ArrayIndexOutOfBoundsException.class)
    public Result arrayIndexOutOfBoundsExceptionHandle(ArrayIndexOutOfBoundsException ex){
        ex.printStackTrace();
        return new Result("666","下标越界了");
    }
    @ExceptionHandler(MyException.class)
    public Result myExceptionHandler(MyException ex) {
        ex.printStackTrace();
        return new Result(ex.getCode(), ex.getMessage());
    }

    @ExceptionHandler(NumberFormatException.class)
    public Result numberFormatExceptionHandle(NumberFormatException ex){
        ex.printStackTrace();
        return new Result("000","转换数字时出现异常");
    }


    @ExceptionHandler(Exception.class)
    public Result exceptionHandle(Exception ex) {
        ex.printStackTrace();
        return new Result("444", "未知错误");
    }
}
